package refactortips.editors.codeSmells;

import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.ui.forms.widgets.Form;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.wb.swt.ResourceManager;
import org.eclipse.wb.swt.SWTResourceManager;

import refactortips.editors.AbstractRefactorTipsEditor;
import refactortips.editors.CommandMouseAdapter;

public class ShotgunSurgeryEditor extends AbstractRefactorTipsEditor {

	protected final FormToolkit formToolkit = new FormToolkit(Display.getDefault());
	
	public ShotgunSurgeryEditor() {
	}

	/**
	 * Create contents of the editor part.
	 * @param parent
	 */
	@Override
	public void createPartControl(Composite parent) {
		
		Form frmCodeSmell = formToolkit.createForm(parent);
		formToolkit.paintBordersFor(frmCodeSmell);
		frmCodeSmell.setText("Shotgun Surgery");
		frmCodeSmell.getBody().setLayout(new FillLayout(SWT.HORIZONTAL));
		
		TabFolder tabFolder = new TabFolder(frmCodeSmell.getBody(), SWT.NONE);
		formToolkit.adapt(tabFolder);
		formToolkit.paintBordersFor(tabFolder);
		
		ScrolledComposite sc = new ScrolledComposite(tabFolder, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
		sc.setExpandHorizontal(true);
	    sc.setExpandVertical(true);
		
		TabItem tbtmDescription = new TabItem(tabFolder, SWT.NONE);
		tbtmDescription.setText("Descri\u00E7\u00E3o");
		
		ScrolledComposite scrolledComposite = new ScrolledComposite(tabFolder, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
		tbtmDescription.setControl(scrolledComposite);
		formToolkit.paintBordersFor(scrolledComposite);
		scrolledComposite.setExpandHorizontal(true);
		scrolledComposite.setExpandVertical(true);
		
		Composite composite_3 = new Composite(scrolledComposite, SWT.NONE);
		formToolkit.adapt(composite_3);
		formToolkit.paintBordersFor(composite_3);
		composite_3.setLayout(null);
		
		Label lblDescription = new Label(composite_3, SWT.NONE);
		lblDescription.setBounds(10, 10, 102, 25);
		lblDescription.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
		lblDescription.setFont(SWTResourceManager.getFont("Segoe UI", 14, SWT.BOLD));
		formToolkit.adapt(lblDescription, true, true);
		lblDescription.setText("Descri\u00E7\u00E3o");
		
		Link linkMoveMethod = new Link(composite_3, SWT.NONE);
		linkMoveMethod.setBounds(548, 267, 97, 21);
		linkMoveMethod.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		formToolkit.adapt(linkMoveMethod, true, true);
		linkMoveMethod.setText("<a>Move Method</a>");
		
		Link linkMoveFIeld = new Link(composite_3, 0);
		linkMoveFIeld.setText("<a>Move Field</a>");
		linkMoveFIeld.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		linkMoveFIeld.setBounds(681, 267, 76, 21);
		formToolkit.adapt(linkMoveFIeld, true, true);
		
		Link linkInlineClass = new Link(composite_3, 0);
		linkInlineClass.setText("<a>Inline Class</a>");
		linkInlineClass.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		linkInlineClass.setBounds(587, 331, 78, 21);
		formToolkit.adapt(linkInlineClass, true, true);
		
		Link linkDivergentChange = new Link(composite_3, 0);
		linkDivergentChange.setText("<a>Divergent Change</a>");
		linkDivergentChange.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		linkDivergentChange.addMouseListener(new CommandMouseAdapter(getSite(), "RefactorTips.commands.divergentChangeCommand"));
		linkDivergentChange.setBounds(751, 79, 125, 21);
		formToolkit.adapt(linkDivergentChange, true, true);
		
		StyledText styledText = new StyledText(composite_3, SWT.READ_ONLY | SWT.WRAP);
		styledText.setEnabled(false);
		styledText.setDoubleClickEnabled(false);
		styledText.setJustify(true);
		styledText.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		styledText.setText("\t\tCirurgia de Espinguarda (Shotgun surgery) \u00E9 semelhante a altera\u00E7\u00E3o divergente (\t\t\t\t\t\t\t\t  ) mas \u00E9 o contr\u00E1rio. Voc\u00EA sente o cheiro disso quando todas as vezes que voc\u00EA faz um tipo de mudan\u00E7a, voc\u00EA tem que fazer v\u00E1rias pequenas altera\u00E7\u00F5es em v\u00E1rias classes diferentes. Quando as altera\u00E7\u00F5es est\u00E3o por todo o lugar, elas s\u00E3o dif\u00EDceis de encontrar e \u00E9 f\u00E1cil deixar escapar uma mudan\u00E7a importante.");
		styledText.setBounds(501, 57, 423, 167);
		formToolkit.adapt(styledText);
		formToolkit.paintBordersFor(styledText);
		
		Label lblNewLabel = new Label(composite_3, SWT.NONE);
		lblNewLabel.setImage(ResourceManager.getPluginImage("RefactorTips", "images/codeSmells/shotgunSurgeon.png"));
		lblNewLabel.setBounds(10, 41, 455, 462);
		formToolkit.adapt(lblNewLabel, true, true);
		
		StyledText styledText_1 = new StyledText(composite_3, SWT.READ_ONLY | SWT.WRAP);
		styledText_1.setText("\t\tNesse caso voc\u00EA dever\u00E1 usar\t\t\t\t\t\t\t\te\t\t\t\t\t\tpara colar todas as altera\u00E7\u00F5es em uma \u00FAnica classe. Se nenhuma classe corrente parece ser uma boa candidata, crie uma. Normalmente voc\u00EA pode usar\t\t\t\t\t\tpara trazer um grupo inteiro de comportamentos juntos. Voc\u00EA gera uma pequena dose de altera\u00E7\u00E3o divergente, mas voc\u00EA pode lidar com isso facilmente.");
		styledText_1.setJustify(true);
		styledText_1.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		styledText_1.setEnabled(false);
		styledText_1.setDoubleClickEnabled(false);
		styledText_1.setBounds(501, 246, 423, 167);
		formToolkit.adapt(styledText_1);
		formToolkit.paintBordersFor(styledText_1);
		
		StyledText styledText_2 = new StyledText(composite_3, SWT.READ_ONLY | SWT.WRAP);
		styledText_2.setText("\t\tAltera\u00E7\u00E3o divergente \u00E9 uma classe que sofre v\u00E1rios tipos de altera\u00E7\u00F5es, e cirurgia de espingarda \u00E9 uma altera\u00E7\u00E3o que altera v\u00E1rias classes. De uma forma ou de outra voc\u00EA deve organizar as coisas para que, idealmente, exista uma liga\u00E7\u00E3o um-para-um entre altera\u00E7\u00F5es comuns e classes.");
		styledText_2.setJustify(true);
		styledText_2.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		styledText_2.setEnabled(false);
		styledText_2.setDoubleClickEnabled(false);
		styledText_2.setBounds(501, 437, 423, 117);
		formToolkit.adapt(styledText_2);
		formToolkit.paintBordersFor(styledText_2);
		scrolledComposite.setContent(composite_3);
		scrolledComposite.setMinSize(composite_3.computeSize(SWT.DEFAULT, SWT.DEFAULT));
		
		TabItem tbtmUsage = new TabItem(tabFolder, SWT.NONE);
		tbtmUsage.setText("Exemplo");
		
		ScrolledComposite scrolledComposite_1 = new ScrolledComposite(tabFolder, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
		tbtmUsage.setControl(scrolledComposite_1);
		formToolkit.paintBordersFor(scrolledComposite_1);
		scrolledComposite_1.setExpandHorizontal(true);
		scrolledComposite_1.setExpandVertical(true);
		
		Composite composite = new Composite(scrolledComposite_1, SWT.NONE);
		formToolkit.adapt(composite);
		formToolkit.paintBordersFor(composite);
		scrolledComposite_1.setContent(composite);
		scrolledComposite_1.setMinSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
		
		TabItem tbtmVideo = new TabItem(tabFolder, SWT.NONE);
		tbtmVideo.setText("Video");
		
		Browser browser = new Browser(tabFolder, SWT.NONE);
		browser.setUrl("");
		tbtmVideo.setControl(browser);
		formToolkit.paintBordersFor(browser);
	}
}
